package com.crm.system.service.impl.user;

import com.crm.common.util.CommonUtils;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.entity.sys.UserCare;
import com.crm.service.sys.UserCareDbService;
import com.crm.system.service.user.UserCareService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Author:chaifuyou
 * @Date: 2021/5/25 11:11
 */
@Service
public class UserCareServiceImpl implements UserCareService {

    @Autowired
    private UserCareDbService userCareDbService;

    /**
     * 添加关注
     * @param careAccountId
     */
    @Override
    public void addUserCare(String careAccountId) {
        UserCare userCare = new UserCare();
        userCare.setCareAccountId(careAccountId);
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        userCare.setUserCareId(CommonUtils.getGUID());
        userCare.setCreatePeopleId(userAccount.getAccountId());
        userCare.setCreateTm(new Date());
        userCareDbService.addUserCare(userCare);
    }

    /**
     * 取消关注
     * @param careAccountId
     */
    @Override
    public void delUserCare(String careAccountId) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        userCareDbService.delUserCare(careAccountId,userAccount.getAccountId());
    }
}
